package com.swak.router;

@FunctionalInterface
@SuppressWarnings({ "rawtypes", "unchecked" })
public interface RouterFunction<T extends Route> {

	HandlerFunction<T> route(T request);

	default RouterFunction<T> and(RouterFunction<T> other) {
		return new RouterFunctions.ComposedRouterFunction(this, other);
	}

	default RouterFunction<?> andOther(RouterFunction<?> other) {
		return new RouterFunctions.DifferentComposedRouterFunction(this, other);
	}
	
	default RouterFunction<T> andRoute(RequestPredicate predicate, HandlerFunction<T> handlerFunction) {
		return and(RouterFunctions.route(predicate, handlerFunction));
	}
	
	default RouterFunction<T> filter(HandlerFilterFunction<T> filterFunction) {
		return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction);
	}
}
